home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWResour / Sources / SLResSin.cpp < prev   
Encoding:
Text File  |  1996-08-16  |  7.1 KB  |  255 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                SLResSin.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWRESACC_H
  13. #include "FWResAcc.h"
  14. #endif
  15.  
  16. #ifndef FWEXCEPT_H
  17. #include "FWExcept.h"
  18. #endif
  19.  
  20. #ifdef FW_BUILD_MAC
  21. #pragma segment fwresour
  22. #endif
  23.  
  24. #include "SLMemSin.xh"
  25.  
  26. /*
  27.  *  This file was generated by the SOM Compiler.
  28.  *  Generated using: 
  29.  *      SOM Emitter emitxtm.dll: 2.33
  30.  */
  31.  
  32. #define FW_OResourceSink_Class_Source
  33. class FW_CPrivResSinRep;
  34. #include "SLResSin.xih"
  35.  
  36.  
  37. #if defined(__MWERKS__) && GENERATING68K
  38. // A hack to work around a bug
  39. #pragma import list somNewObjectInstance
  40. #endif
  41.  
  42.  
  43. //========================================================================================
  44. // class FW_CPrivResSinRep
  45. //========================================================================================
  46.  
  47. class FW_CPrivResSinRep
  48. {
  49. public:
  50.     FW_DECLARE_AUTO(FW_CPrivResSinRep)
  51.  
  52.     FW_CAcquireResourceData fResource;
  53.     FW_OMemorySink*            fMemorySink;
  54.  
  55.     FW_CPrivResSinRep(Environment* ev, FW_OResource* theResource);
  56.     ~FW_CPrivResSinRep();
  57. };
  58.  
  59.  
  60. FW_DEFINE_AUTO(FW_CPrivResSinRep)
  61.  
  62. //----------------------------------------------------------------------------------------
  63. // FW_CPrivResSinRep::FW_CPrivResSinRep
  64. //----------------------------------------------------------------------------------------
  65.  
  66. inline FW_CPrivResSinRep::FW_CPrivResSinRep(Environment* ev, FW_OResource* theResource) :
  67.     fResource(ev, theResource)
  68. {
  69.     long resourceSize = fResource.GetSize();
  70.  
  71.     fMemorySink = new FW_OMemorySink;
  72.     fMemorySink->InitFromBuffer(ev, fResource.GetData(), resourceSize, resourceSize);
  73.  
  74.     FW_END_CONSTRUCTOR
  75. }
  76.  
  77.  
  78. //----------------------------------------------------------------------------------------
  79. // FW_CPrivResSinRep::~FW_CPrivResSinRep
  80. //----------------------------------------------------------------------------------------
  81.  
  82. inline FW_CPrivResSinRep::~FW_CPrivResSinRep()
  83. {
  84.     FW_START_DESTRUCTOR
  85.     delete fMemorySink;
  86. }
  87.  
  88.  
  89. //----------------------------------------------------------------------------------------
  90. // FW_OResourceSink__InitFromOResource
  91. //----------------------------------------------------------------------------------------
  92.  
  93. SOM_Scope void  SOMLINK FW_OResourceSink__InitFromOResource(FW_OResourceSink *somSelf, Environment *ev,
  94.         FW_OResource* theResource)
  95. {
  96.     FW_OResourceSinkData *somThis = FW_OResourceSinkGetData(somSelf);
  97.  
  98.     FW_SOM_TRY
  99.     {
  100.         somThis->fRep = FW_NEW(FW_CPrivResSinRep, (ev, theResource));
  101.     }
  102.     FW_SOM_CATCH
  103. }
  104.  
  105.  
  106. //----------------------------------------------------------------------------------------
  107. // FW_OResourceSink__somInit
  108. //----------------------------------------------------------------------------------------
  109.  
  110. SOM_Scope void  SOMLINK FW_OResourceSink__somInit(FW_OResourceSink *somSelf)
  111. {
  112.     FW_OResourceSinkData *somThis = FW_OResourceSinkGetData(somSelf);
  113.  
  114.     FW_OResourceSink_parent_FW_ORandomAccessSink_somInit(somSelf);
  115. }
  116.  
  117.  
  118. //----------------------------------------------------------------------------------------
  119. // FW_OResourceSink__somUninit
  120. //----------------------------------------------------------------------------------------
  121.  
  122. SOM_Scope void  SOMLINK FW_OResourceSink__somUninit(FW_OResourceSink *somSelf)
  123. {
  124.     FW_OResourceSinkData *somThis = FW_OResourceSinkGetData(somSelf);
  125.  
  126.     FW_SOM_UNINIT_TRY
  127.     {
  128.         delete somThis->fRep;
  129.         FW_OResourceSink_parent_FW_ORandomAccessSink_somUninit(somSelf);
  130.     }
  131.     FW_SOM_UNINIT_CATCH
  132. }
  133.  
  134.  
  135. //----------------------------------------------------------------------------------------
  136. // FW_OResourceSink__Read
  137. //----------------------------------------------------------------------------------------
  138.  
  139. SOM_Scope void  SOMLINK FW_OResourceSink__Read(FW_OResourceSink *somSelf, Environment *ev,
  140.         void* destination,
  141.         long count)
  142. {
  143.     FW_OResourceSinkData *somThis = FW_OResourceSinkGetData(somSelf);
  144.     FW_CPrivResSinRep& rep = *somThis->fRep;
  145.  
  146.     FW_SOM_TRY
  147.     {
  148.         rep.fMemorySink->Read(ev, destination, count);
  149.     }
  150.     FW_SOM_CATCH
  151. }
  152.  
  153.  
  154. //----------------------------------------------------------------------------------------
  155. // FW_OResourceSink__GetWritableBytes
  156. //----------------------------------------------------------------------------------------
  157.  
  158. SOM_Scope long  SOMLINK FW_OResourceSink__GetWritableBytes(FW_OResourceSink *somSelf, Environment *ev)
  159. {
  160. FW_UNUSED(ev);
  161.     FW_OResourceSinkData *somThis = FW_OResourceSinkGetData(somSelf);
  162.  
  163.     // Resource sinks are read-only
  164.     return 0;
  165. }
  166.  
  167.  
  168. //----------------------------------------------------------------------------------------
  169. // FW_OResourceSink__Write
  170. //----------------------------------------------------------------------------------------
  171.  
  172. SOM_Scope void  SOMLINK FW_OResourceSink__Write(FW_OResourceSink *somSelf, Environment *ev,
  173.         void* source,
  174.         long count)
  175. {
  176. FW_UNUSED(ev);
  177. FW_UNUSED(source);
  178. FW_UNUSED(count);
  179.     FW_OResourceSinkData *somThis = FW_OResourceSinkGetData(somSelf);
  180.  
  181.     FW_ASSERT(("Resource sinks are read-only", FALSE));
  182. }
  183.  
  184.  
  185. //----------------------------------------------------------------------------------------
  186. // FW_OResourceSink__GetLength
  187. //----------------------------------------------------------------------------------------
  188.  
  189. SOM_Scope long  SOMLINK FW_OResourceSink__GetLength(FW_OResourceSink *somSelf, Environment *ev)
  190. {
  191.     FW_OResourceSinkData *somThis = FW_OResourceSinkGetData(somSelf);
  192.     FW_CPrivResSinRep& rep = *somThis->fRep;
  193.  
  194.     FW_SOM_TRY
  195.     {
  196.         return rep.fMemorySink->GetLength(ev);
  197.     }
  198.     FW_SOM_CATCH
  199.     return 0;
  200. }
  201.  
  202.  
  203. //----------------------------------------------------------------------------------------
  204. // FW_OResourceSink__SetLength
  205. //----------------------------------------------------------------------------------------
  206.  
  207. SOM_Scope void  SOMLINK FW_OResourceSink__SetLength(FW_OResourceSink *somSelf, Environment *ev,
  208.         long length)
  209. {
  210.     FW_OResourceSinkData *somThis = FW_OResourceSinkGetData(somSelf);
  211.     FW_CPrivResSinRep& rep = *somThis->fRep;
  212.  
  213.     FW_SOM_TRY
  214.     {
  215.         rep.fMemorySink->SetLength(ev, length);
  216.     }
  217.     FW_SOM_CATCH
  218. }
  219.  
  220.  
  221. //----------------------------------------------------------------------------------------
  222. // FW_OResourceSink__GetPosition
  223. //----------------------------------------------------------------------------------------
  224.  
  225. SOM_Scope long  SOMLINK FW_OResourceSink__GetPosition(FW_OResourceSink *somSelf, Environment *ev)
  226. {
  227.     FW_OResourceSinkData *somThis = FW_OResourceSinkGetData(somSelf);
  228.     FW_CPrivResSinRep& rep = *somThis->fRep;
  229.  
  230.     FW_SOM_TRY
  231.     {
  232.         return rep.fMemorySink->GetPosition(ev);
  233.     }
  234.     FW_SOM_CATCH
  235.     return 0;
  236. }
  237.  
  238.  
  239. //----------------------------------------------------------------------------------------
  240. // FW_OResourceSink__SetPosition
  241. //----------------------------------------------------------------------------------------
  242.  
  243. SOM_Scope void  SOMLINK FW_OResourceSink__SetPosition(FW_OResourceSink *somSelf, Environment *ev,
  244.         long position)
  245. {
  246.     FW_OResourceSinkData *somThis = FW_OResourceSinkGetData(somSelf);
  247.     FW_CPrivResSinRep& rep = *somThis->fRep;
  248.  
  249.     FW_SOM_TRY
  250.     {
  251.         rep.fMemorySink->SetPosition(ev, position);
  252.     }
  253.     FW_SOM_CATCH
  254. }
  255.